#import "sprite_dialog.h"

#import "music.h"
#import "layer_dialog.h"

#define SPRITE_DIALOG_ACTION_TIME 1.5f

@implementation SpriteDialog

@synthesize handleLayer = handleLayer_;

- (id)initSpriteDialog
{
	if ((self = [super init]))
	{
		actionType_ = ACTION_TYPE_SCALE_Y;
		backgroundRect_ = CGSizeMake(g_ScreenSize.width, 200.0f);
	}
	return self;
}

- (void)draw
{
	UICenterRect _Rect;

	_Rect.center = CGPointZero;
	_Rect.size = g_ScrrenSize;
	glColor4f(0.0f, 0.0f, 0.0f, 0.8f);
	uiRenderRect(_Rect);
}

- (void)touchBegan:(CGPoint) Point
{
}

- (void)touchMoved:(CGPoint) Point
{
}

- (void)touchEnded:(CGPoint) Point
{
	[self actionClose];
}

- (void)actionOpen
{
	CCSequence *seq;
	id action;
	CCCallFunc *callBack;

	switch (actionType_)
	{
	case ACTION_TYPE_SCALE_X:
		self.scaleX = 0.0f;
		self.scaleY = 1.0f;
		break;
	case ACTION_TYPE_SCALE_Y:
		self.scaleX = 1.0f;
		self.scaleY = 0.0f;
		break;
	case ACTION_TYPE_SCALE_XY:
		self.scale = 0.0f;
		break;
	default: NSAssert(FALSE);
	}
	action = [CCScaleTo actionWithDuration:SPRITE_DIALOG_ACTION_TIME scaleX:1.0f scaleY:1.0f];
	callBack = [CCCallFunc actionWithTarget:self selector:@selector(callBackOpenOver)];
	seq = [CCSequence actions:action, callBack, nil];
	[self runAction:seq];
}

- (void)actionClose
{
	CCSequence *seq;
	id action;
	CCCallFunc *callBack;

	switch (actionType_)
	{
	case ACTION_TYPE_SCALE_X: action = [CCScaleTo actionWithDuration:SPRITE_DIALOG_ACTION_TIME scaleX:0.0f scaleY:1.0f]; break;
	case ACTION_TYPE_SCALE_Y: action = [CCScaleTo actionWithDuration:SPRITE_DIALOG_ACTION_TIME scaleX:1.0f scaleY:0.0f]; break;
	case ACTION_TYPE_SCALE_XY: action = [CCScaleTo actionWithDuration:SPRITE_DIALOG_ACTION_TIME scaleX:0.0f scaleY:0.0f]; break;
	default: NSAssert(FALSE);
	}
	callBack = [CCCallFunc actionWithTarget:self selector:@selector(callBackOpenOver)];
	seq = [CCSequence actions:action, callBack, nil];
	[self runAction:seq];
}

- (void)actionOpenOver
{
}

- (void)actionCloseOver
{
}

- (void)callBackOpenOver 
{
	[self actionOpenOver];
}

- (void)callBackCloseOver
{
	EffectButton();
	[self actionCloseOver];
	[handleLayer_ stopDialog];
}

@end